package com.lsj.controller;

import com.lsj.util.VerifyCodeUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.image.BufferedImage;

@RestController
public class VerifyCodeController {

    @GetMapping("/vercode")
    public void getCode(HttpServletRequest request, HttpServletResponse response) throws Exception{
        VerifyCodeUtils codeUtils = new VerifyCodeUtils();
        BufferedImage image = codeUtils.getImage();
        String text = codeUtils.getText();
        HttpSession session = request.getSession();
        session.setAttribute("index_code",text);
        VerifyCodeUtils.output(image,response.getOutputStream());
    }


}
